package com.base.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.comm.CommContent;
import com.base.po.voip.Abouts;
import com.base.service.AboutsService;
import com.base.service.LogsService;
import com.base.utils.IP;

/**
 * 
 * 联系我们 添加-修改
 * 
 * @author f 优化日期：10-11
 * 
 */
@Controller
@RequestMapping("/admin")
public class AboutsUpdateController {

	@Autowired
	private LogsService logsService; // 日志Service
	@Autowired
	private AboutsService aboutsService; // 联系我们Service

	// 联系我们 添加-修改
	@RequestMapping(value = "/abouts_do_update", method = RequestMethod.POST)
	public @ResponseBody int doUpdate(HttpServletRequest request, @RequestBody Abouts abouts) {
		HttpSession session = request.getSession(false); // 获取session
		if (session == null) {
			return -1;
		}
		Object obj_id = session.getAttribute("adminUserId"); // 登录ID
		Object obj_name = session.getAttribute("userNick"); // 登录名称
		if (obj_id == null || obj_name == null) {
			return -1;
		}
		String userid = (String) obj_id;
		String username = (String) obj_name;
		int flag; // 成功状态
		if (aboutsService.selectByPrimaryKey(abouts.getId()) == null) {
			abouts.setAgentid(userid); // 设置参数 代理商ID
			abouts.setAgentname(username); // 代理商名称
			abouts.setDatastatus(true); // 数据状态
			flag = aboutsService.insertSelective(abouts); // 新增
		} else {
			flag = aboutsService.updateByPrimaryKeySelective(abouts); // 修改
		}
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "改动联系我们信息", username, true,
				IP.getIpAddr(request));
		return flag;
	}
}
